package com.atguigu.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.entity.Dict;
import com.atguigu.result.Result;
import com.atguigu.service.DictService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/dict")
public class DictController {
    @Reference
    private DictService dictService;
    @RequestMapping
    public String index(){
        return "dict/index";
    }
//    获取数据字典的数据
    @ResponseBody
    @RequestMapping("/findZnodes")
    public Result findZnodes(@RequestParam(value = "id",defaultValue = "0") Long id){
        List<Map<String,Object>> zNodes=dictService.findZnodes(id);
        return Result.ok(zNodes);
    }
//    根据父id获取所有子节点
    @ResponseBody
    @RequestMapping("/findListByParentId/{areaId}")
    public Result findListByParentId(@PathVariable("areaId") Long id){
        List<Dict> listByParentId = dictService.findListByParentId(id);
        return Result.ok(listByParentId);
    }
}
